﻿$(document).ready(function () {
    var opening = false;
    var settingsButton = $('.footer-menu-item.sign-in, .footer-menu-item.settings');
    var popupContainer = $('#settings-menu-container');
    settingsButton.click(function () {
        var newState = popupContainer.css('display') == 'none' ? 'block' : 'none';

        opening = newState == 'block';
        if (opening) {

            if (settingsButton.hasClass('settings-button')) {
                settingsButton.addClass('settings-button-active');
            } else if (settingsButton.hasClass('signin-button')) {
                settingsButton.addClass('signin-button-active');
            }
            settingsButton.addClass('footer-button-active');

            popupContainer.slideToggle('slow');
        }
    });
    $(document).click(function () {
        if (!opening) {
            if (popupContainer.css('display') != 'none') {
                popupContainer.slideToggle('slow');
            }

            if (settingsButton.hasClass('settings-button')) {
                settingsButton.removeClass('settings-button-active');
            } else if (settingsButton.hasClass('signin-button')) {
                settingsButton.removeClass('signin-button-active');
            }

            settingsButton.removeClass('footer-button-active');
        }
        opening = false;
    });
});